//
// Created by xili on 2024/8/28 16:50.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int longestOnes(vector<int> &nums, int k) {
        int n = nums.size();
        int l = 0;
        int cnt = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            cnt += 1 - nums[i];
            while (cnt > k) {
                cnt -= 1 - nums[l++];
            }
            ans = max(ans, i - l + 1);
        }
        return ans;
    }
};